<?php

// Config file for the PHP Web Proxy

define('INDEX_FILE_NAME', 'index.php'); // Name of the default file
define('URL_PARAM_NAME', 'proxy_url');  // The parameter name used for the proxy URL.

/* === LOGGING PROPERTIES === */
define('LOG_FILE',         dirname(__FILE__) . '/../logs/proxy.log'); // The path to the log file.
define('LINE_BREAK',       "\n"); // Which line break character should be used.
define('DATE_FORMAT',      'd-m-Y H:i:s'); // The date format for the log entry
define('LOG_LEVEL',        0); // 0 = Debug (Lowest), 4 = Fatal (Highest)
define('LOG_MAX_SIZE',     100); // Maximum log file size in KB. Set to 0 for unlimited.
define('MAX_LOG_BACKUPS',  5); // The number of log files to keep.
function getMime($ext){
	$mimes = array(	'hqx'	=>	'application/mac-binhex40',
				'cpt'	=>	'application/mac-compactpro',
				'csv'	=>	array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
				'bin'	=>	'application/macbinary',
				'dms'	=>	'application/octet-stream',
				'lha'	=>	'application/octet-stream',
				'lzh'	=>	'application/octet-stream',
				'exe'	=>	array('application/octet-stream', 'application/x-msdownload'),
				'class'	=>	'application/octet-stream',
				'psd'	=>	'application/x-photoshop',
				'so'	=>	'application/octet-stream',
				'sea'	=>	'application/octet-stream',
				'dll'	=>	'application/octet-stream',
				'oda'	=>	'application/oda',
				'pdf'	=>	array('application/pdf', 'application/x-download'),
				'ai'	=>	'application/postscript',
				'eps'	=>	'application/postscript',
				'ps'	=>	'application/postscript',
				'smi'	=>	'application/smil',
				'smil'	=>	'application/smil',
				'mif'	=>	'application/vnd.mif',
				'xls'	=>	array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
				'ppt'	=>	array('application/powerpoint', 'application/vnd.ms-powerpoint'),
				'wbxml'	=>	'application/wbxml',
				'wmlc'	=>	'application/wmlc',
				'dcr'	=>	'application/x-director',
				'dir'	=>	'application/x-director',
				'dxr'	=>	'application/x-director',
				'dvi'	=>	'application/x-dvi',
				'gtar'	=>	'application/x-gtar',
				'gz'	=>	'application/x-gzip',
				'php'	=>	'application/x-httpd-php',
				'php4'	=>	'application/x-httpd-php',
				'php3'	=>	'application/x-httpd-php',
				'phtml'	=>	'application/x-httpd-php',
				'phps'	=>	'application/x-httpd-php-source',
				'js'	=>	'application/x-javascript',
				'swf'	=>	'application/x-shockwave-flash',
				'sit'	=>	'application/x-stuffit',
				'tar'	=>	'application/x-tar',
				'tgz'	=>	array('application/x-tar', 'application/x-gzip-compressed'),
				'xhtml'	=>	'application/xhtml+xml',
				'xht'	=>	'application/xhtml+xml',
				'zip'	=>  array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
				'mid'	=>	'audio/midi',
				'midi'	=>	'audio/midi',
				'mpga'	=>	'audio/mpeg',
				'mp2'	=>	'audio/mpeg',
				'mp3'	=>	array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
				'aif'	=>	'audio/x-aiff',
				'aiff'	=>	'audio/x-aiff',
				'aifc'	=>	'audio/x-aiff',
				'ram'	=>	'audio/x-pn-realaudio',
				'rm'	=>	'audio/x-pn-realaudio',
				'rpm'	=>	'audio/x-pn-realaudio-plugin',
				'ra'	=>	'audio/x-realaudio',
				'rv'	=>	'video/vnd.rn-realvideo',
				'wav'	=>	'audio/x-wav',
				'bmp'	=>	'image/bmp',
				'gif'	=>	'image/gif',
				'jpeg'	=>	array('image/jpeg', 'image/pjpeg'),
				'jpg'	=>	array('image/jpeg', 'image/pjpeg'),
				'jpe'	=>	array('image/jpeg', 'image/pjpeg'),
				'png'	=>	array('image/png',  'image/x-png'),
				'tiff'	=>	'image/tiff',
				'tif'	=>	'image/tiff',
				'css'	=>	'text/css',
				'html'	=>	'text/html',
				'htm'	=>	'text/html',
				'shtml'	=>	'text/html',
				'txt'	=>	'text/plain',
				'text'	=>	'text/plain',
				'log'	=>	array('text/plain', 'text/x-log'),
				'rtx'	=>	'text/richtext',
				'rtf'	=>	'text/rtf',
				'xml'	=>	'text/xml',
				'xsl'	=>	'text/xml',
				'mpeg'	=>	'video/mpeg',
				'mpg'	=>	'video/mpeg',
				'mpe'	=>	'video/mpeg',
				'qt'	=>	'video/quicktime',
				'mov'	=>	'video/quicktime',
				'avi'	=>	'video/x-msvideo',
				'movie'	=>	'video/x-sgi-movie',
				'doc'	=>	'application/msword',
				'docx'	=>	'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
				'xlsx'	=>	'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
				'word'	=>	array('application/msword', 'application/octet-stream'),
				'xl'	=>	'application/excel',
				'eml'	=>	'message/rfc822',
				'json' => array('application/json', 'text/json')
			);

	if(!isset($mimes[$ext]))
		return false;
	return $mimes[$ext];
}
function encodeURIComponent($string) {
   $result = "";
   for ($i = 0; $i < strlen($string); $i++) {
      $result .= encodeURIComponentbycharacter(urlencode($string[$i]));
   }
   return $result;
}
function encodeURIComponentbycharacter($char) { if ($char == "+") { return "%20"; } if ($char == "%21") { return "!"; } if ($char == "%27") { return '"'; } if ($char == "%28") { return "("; } if ($char == "%29") { return ")"; } if ($char == "%2A") { return "*"; } if ($char == "%7E") { return "~"; } if ($char == "%80") { return "%E2%82%AC"; } if ($char == "%81") { return "%C2%81"; } if ($char == "%82") { return "%E2%80%9A"; } if ($char == "%83") { return "%C6%92"; } if ($char == "%84") { return "%E2%80%9E"; } if ($char == "%85") { return "%E2%80%A6"; } if ($char == "%86") { return "%E2%80%A0"; } if ($char == "%87") { return "%E2%80%A1"; } if ($char == "%88") { return "%CB%86"; } if ($char == "%89") { return "%E2%80%B0"; } if ($char == "%8A") { return "%C5%A0"; } if ($char == "%8B") { return "%E2%80%B9"; } if ($char == "%8C") { return "%C5%92"; } if ($char == "%8D") { return "%C2%8D"; } if ($char == "%8E") { return "%C5%BD"; } if ($char == "%8F") { return "%C2%8F"; } if ($char == "%90") { return "%C2%90"; } if ($char == "%91") { return "%E2%80%98"; } if ($char == "%92") { return "%E2%80%99"; } if ($char == "%93") { return "%E2%80%9C"; } if ($char == "%94") { return "%E2%80%9D"; } if ($char == "%95") { return "%E2%80%A2"; } if ($char == "%96") { return "%E2%80%93"; } if ($char == "%97") { return "%E2%80%94"; } if ($char == "%98") { return "%CB%9C"; } if ($char == "%99") { return "%E2%84%A2"; } if ($char == "%9A") { return "%C5%A1"; } if ($char == "%9B") { return "%E2%80%BA"; } if ($char == "%9C") { return "%C5%93"; } if ($char == "%9D") { return "%C2%9D"; } if ($char == "%9E") { return "%C5%BE"; } if ($char == "%9F") { return "%C5%B8"; } if ($char == "%A0") { return "%C2%A0"; } if ($char == "%A1") { return "%C2%A1"; } if ($char == "%A2") { return "%C2%A2"; } if ($char == "%A3") { return "%C2%A3"; } if ($char == "%A4") { return "%C2%A4"; } if ($char == "%A5") { return "%C2%A5"; } if ($char == "%A6") { return "%C2%A6"; } if ($char == "%A7") { return "%C2%A7"; } if ($char == "%A8") { return "%C2%A8"; } if ($char == "%A9") { return "%C2%A9"; } if ($char == "%AA") { return "%C2%AA"; } if ($char == "%AB") { return "%C2%AB"; } if ($char == "%AC") { return "%C2%AC"; } if ($char == "%AD") { return "%C2%AD"; } if ($char == "%AE") { return "%C2%AE"; } if ($char == "%AF") { return "%C2%AF"; } if ($char == "%B0") { return "%C2%B0"; } if ($char == "%B1") { return "%C2%B1"; } if ($char == "%B2") { return "%C2%B2"; } if ($char == "%B3") { return "%C2%B3"; } if ($char == "%B4") { return "%C2%B4"; } if ($char == "%B5") { return "%C2%B5"; } if ($char == "%B6") { return "%C2%B6"; } if ($char == "%B7") { return "%C2%B7"; } if ($char == "%B8") { return "%C2%B8"; } if ($char == "%B9") { return "%C2%B9"; } if ($char == "%BA") { return "%C2%BA"; } if ($char == "%BB") { return "%C2%BB"; } if ($char == "%BC") { return "%C2%BC"; } if ($char == "%BD") { return "%C2%BD"; } if ($char == "%BE") { return "%C2%BE"; } if ($char == "%BF") { return "%C2%BF"; } if ($char == "%C0") { return "%C3%80"; } if ($char == "%C1") { return "%C3%81"; } if ($char == "%C2") { return "%C3%82"; } if ($char == "%C3") { return "%C3%83"; } if ($char == "%C4") { return "%C3%84"; } if ($char == "%C5") { return "%C3%85"; } if ($char == "%C6") { return "%C3%86"; } if ($char == "%C7") { return "%C3%87"; } if ($char == "%C8") { return "%C3%88"; } if ($char == "%C9") { return "%C3%89"; } if ($char == "%CA") { return "%C3%8A"; } if ($char == "%CB") { return "%C3%8B"; } if ($char == "%CC") { return "%C3%8C"; } if ($char == "%CD") { return "%C3%8D"; } if ($char == "%CE") { return "%C3%8E"; } if ($char == "%CF") { return "%C3%8F"; } if ($char == "%D0") { return "%C3%90"; } if ($char == "%D1") { return "%C3%91"; } if ($char == "%D2") { return "%C3%92"; } if ($char == "%D3") { return "%C3%93"; } if ($char == "%D4") { return "%C3%94"; } if ($char == "%D5") { return "%C3%95"; } if ($char == "%D6") { return "%C3%96"; } if ($char == "%D7") { return "%C3%97"; } if ($char == "%D8") { return "%C3%98"; } if ($char == "%D9") { return "%C3%99"; } if ($char == "%DA") { return "%C3%9A"; } if ($char == "%DB") { return "%C3%9B"; } if ($char == "%DC") { return "%C3%9C"; } if ($char == "%DD") { return "%C3%9D"; } if ($char == "%DE") { return "%C3%9E"; } if ($char == "%DF") { return "%C3%9F"; } if ($char == "%E0") { return "%C3%A0"; } if ($char == "%E1") { return "%C3%A1"; } if ($char == "%E2") { return "%C3%A2"; } if ($char == "%E3") { return "%C3%A3"; } if ($char == "%E4") { return "%C3%A4"; } if ($char == "%E5") { return "%C3%A5"; } if ($char == "%E6") { return "%C3%A6"; } if ($char == "%E7") { return "%C3%A7"; } if ($char == "%E8") { return "%C3%A8"; } if ($char == "%E9") { return "%C3%A9"; } if ($char == "%EA") { return "%C3%AA"; } if ($char == "%EB") { return "%C3%AB"; } if ($char == "%EC") { return "%C3%AC"; } if ($char == "%ED") { return "%C3%AD"; } if ($char == "%EE") { return "%C3%AE"; } if ($char == "%EF") { return "%C3%AF"; } if ($char == "%F0") { return "%C3%B0"; } if ($char == "%F1") { return "%C3%B1"; } if ($char == "%F2") { return "%C3%B2"; } if ($char == "%F3") { return "%C3%B3"; } if ($char == "%F4") { return "%C3%B4"; } if ($char == "%F5") { return "%C3%B5"; } if ($char == "%F6") { return "%C3%B6"; } if ($char == "%F7") { return "%C3%B7"; } if ($char == "%F8") { return "%C3%B8"; } if ($char == "%F9") { return "%C3%B9"; } if ($char == "%FA") { return "%C3%BA"; } if ($char == "%FB") { return "%C3%BB"; } if ($char == "%FC") { return "%C3%BC"; } if ($char == "%FD") { return "%C3%BD"; } if ($char == "%FE") { return "%C3%BE"; } if ($char == "%FF") { return "%C3%BF"; } return $char; }

/* === Access Control === */

// White list and black list are based on domain name.
// 'domain.com' will match *exactly* domain.com
// '.domain.com' will match domain.com *and* all subdomains
// if your expression starts with a '/' it is treated as a regular expression - and will be checked against the WHOLE URL
// 
$WHITE_LIST = array();
$BLACK_LIST = array();

$BAN_LIST = array(); // an array of Regular Expressions matching IP addresses. For example. 10\.0\.0\..* would match all addresses coming from 10.0.0.0 subnet

?>